<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>INSPINIA | File Upload</title>

    <link href="/iLink/css/bootstrap.min.css" rel="stylesheet">
    <link href="/iLink/font-awesome/css/font-awesome.css" rel="stylesheet">
    <link href="/iLink/css/animate.css" rel="stylesheet">
    <link href="/iLink/css/plugins/dropzone/basic.css" rel="stylesheet">
    <link href="/iLink/css/plugins/dropzone/dropzone.css" rel="stylesheet">
    <link href="/iLink/css/style.css" rel="stylesheet">
    <link href="/iLink/css/plugins/sweetalert/sweetalert.css"
          rel="stylesheet">

</head>

<body>

<div class="row border-bottom"></div>
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>File upload</h2>
        <ol class="breadcrumb">
            <li><a href="index.html">Home</a></li>
            <li><a>Forms</a></li>
            <li class="active"><strong>File upload</strong></li>
        </ol>
    </div>
    <div class="col-lg-2"></div>
</div>
<div class="wrapper wrapper-content animated fadeIn">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>Dropzone Area</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link"> <i class="fa fa-chevron-up"></i>
                        </a> <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                        <i class="fa fa-wrench"></i>
                    </a>
                        <ul class="dropdown-menu dropdown-user">
                            <li><a href="#">Config option 1</a></li>
                            <li><a href="#">Config option 2</a></li>
                        </ul>
                        <a class="close-link"> <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form id="uploadForm" enctype="multipart/form-data">
                        <table>
                            <tr>
                                <td>文件描述:</td>
                                <td><input type="text" name="description"  class="form-control"></td>
                            </tr>
                            <tr>
                                <td>请选择文件:</td>
                                <td><input type="file" name="file"  class="form-control"></td>
                            </tr>
                            <tr>
                                <td colspan="2"><input id="upload" type="submit" value="上传" class="btn btn-block btn-outline btn-primary"> </td>
                            </tr>
                        </table>
                    </form>
                    <div>
                        <div class="m text-right">
                            <small>Github: <a
                                    href="https://github.com/xx132917/iLink" target="_blank">https://github.com/xx132917/iLink</a>
                            </small>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>





<!-- Mainly scripts -->
<script src="/iLink/js/jquery-2.1.1.js"></script>
<script src="/iLink/js/bootstrap.min.js"></script>
<script src="/iLink/js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="/iLink/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>

<!-- Custom and plugin javascript -->
<script src="/iLink/js/inspinia.js"></script>
<script src="/iLink/js/plugins/pace/pace.min.js"></script>

<!-- DROPZONE -->
<script src="/iLink/js/plugins/dropzone/dropzone.js"></script>
<script src="/iLink/js/plugins/sweetalert/sweetalert.min.js"></script>

<script>
    $(document).ready(
        function() {

            Dropzone.options.myAwesomeDropzone = {

                autoProcessQueue : false,
                uploadMultiple : true,
                parallelUploads : 100,
                maxFiles : 100,

                // Dropzone settings
                init : function() {
                    var myDropzone = this;

                    this.element.querySelector("button[type=submit]")
                        .addEventListener("click", function(e) {
                            e.preventDefault();
                            e.stopPropagation();
                            myDropzone.processQueue();
                        });
                    this.on("sendingmultiple", function() {
                    });
                    this.on("successmultiple",
                        function(files, response) {
                        });
                    this.on("errormultiple", function(files, response) {
                    });
                }

            }

        });

    $(function() {
        $("#upload").click(function() {
            var formData = new FormData($('#uploadForm')[0]);
            alert(formData);
            /*$.ajax({
                type : 'post',
                url : "/iLink/file/upload",
                data : formData,
                cache : false,
                processData : false,
                contentType : false,
                /!* success : function(d) {
                    //var rdata = JSON.parse(d);
                    //alert(d);
                    if (d == "success") {
                        swal("成功!", "上传成功:)", "success");
                    } else {
                        swal("失败", "上传失败:(", "error");
                    }
                } *!/
            }).success(function (data) {
                console.log(data);
              }).error(function () {
              alert("上传失败");
              }); */
            $.post("/iLink/file/upload", formData, function (d) {
                alert(1);
                if (d == "success") {
                    swal("成功!", "上传成功:)", "success");
                } else {
                    swal("失败", "上传失败:(", "error");
                }
            })
        });
    });

</script>

</body>

</html>
